/**
 * @file shell_port.c
 * @author Letter (NevermindZZT@gmail.com)
 * @brief 
 * @version 0.1
 * @date 2019-02-22
 * 
 * @Copyright (c) 2019 Unicook
 * 
 */

#include "shell.h"
#include "shell_port.h"
#include "stdio.h"
#include "usart.h"
#include "led.h" 


Shell shell;
char shellBuffer[512];

short userShellWrite( char *data, unsigned short len )
{
	return USART1_driver_write( (uint8_t*)data, len, 0 );
}

short userShellRead( char *data, unsigned short len )
{
	return USART1_driver_read( (uint8_t*)data, len, 0 );
}

void User_Shell_Init(void)
{
	shell.write = userShellWrite;
	shell.read = userShellRead;
	shellInit(&shell, shellBuffer, 512);
}

int func(int argc, char *agrv[])
{
    printf("%dparameter(s)\r\n", argc);
    for (char i = 0; i < argc; i++)
    {
        printf("argument %d --- %s\r\n", i, agrv[i]);
    }
		return 0;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), func, func, test);

int led(int argc, char *agrv[])
{
	if( argc != 2 )
	{
		printf( "Input param error!\r\n" );
	}
	if( *agrv[1] == '0' )
	{
		LED0 = 1;
	}
	else if( *agrv[1] == '1' )
	{
		LED0 = 0;
	}
	return 0;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), led, led, test);

